using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using System.Linq;
using AzureProvider.SoupMethods;

namespace BlogEngine.Core.Providers
{
    public partial class AzureBlogProvider : BlogProvider
	{
        ProfileMethods ProfileMethods = new ProfileMethods();

		public override AuthorProfile SelectProfile(string id)
		{
            return (AuthorProfile)ProfileMethods.GetObject(id, out errMessage); 
		}

		public override void InsertProfile(AuthorProfile profile)
		{
            ProfileMethods.Insert(profile, out errMessage);
		}

		public override void UpdateProfile(AuthorProfile profile)
        {
            DeleteProfile(profile);
            ProfileMethods.Update (profile, out errMessage);
		}

		public override void DeleteProfile(AuthorProfile profile)
		{
            ProfileMethods.Delete (profile.Id );

			if (AuthorProfile.Profiles.Contains(profile))
				AuthorProfile.Profiles.Remove(profile);
		}

		public override List<AuthorProfile> FillProfiles()
		{
            List<AuthorProfile> profiles =
                ProfileMethods.GetObjects(null, out errMessage).Cast<AuthorProfile>().ToList<AuthorProfile>();
            foreach (AuthorProfile o in profiles)
            {
                o.MarkOld();
            }
            return profiles;
		}
	}
}
